<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>后台管理系统</title>
	    <meta name="author" content="BaiYY"/>
	    <meta charset="utf-8">
	    <meta http-equiv="X-UA-Compatible" content="IE=edge">
	    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
	    <meta name="renderer" content="webkit">
	    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/bootstrap.min.css"/>
		<link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/bootstrap-datetimepicker.min.css"/>
		<link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/Font/css/font-awesome.min.css"/>
	    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/index.css"/>
	    <script type="text/javascript" src="__PUBLIC__/admin/js/jquery.js"></script>
	    <script type="text/javascript" src="__PUBLIC__/admin/js/bootstrap.min.js"></script>
	    <script type="text/javascript" src="__PUBLIC__/admin/js/index.js"></script>
		<script type="text/javascript" src="__PUBLIC__/admin/js/time.js"></script>
	    <script type="text/javascript" src="__PUBLIC__/admin/js/bootstrap-paginator.js"></script>
		<script type="text/javascript" src="__PUBLIC__/admin/js/bootstrap-datetimepicker.min.js"></script>
		<script type="text/javascript" src="__PUBLIC__/admin/js/locales/bootstrap-datetimepicker.zh-CN.js"></script>
	</head>
	<body>
		<!--右边侧栏开始-->
		<div class="right-sidebar" style="max-width: 1200px;">
			<ul class="nav nav-tabs" style="margin-bottom: 16px" role="tablist">
				<li role="presentation"><a href="aUser.html">代理审核</a></li>
				<li role="presentation"><a href="agentUserList.html">代理列表</a></li>
				<li role="presentation"><a href="agentUserSearch.html">代理搜索</a></li>
				<li role="presentation" class="active"><a href="agentUserBuy.html">购买记录</a></li>
				<li role="presentation"><a href="agentUserSell.html">充值记录</a></li>
			</ul>

			<div class="admin_tab_cont table-responsive" style="display:block;" id="tab1">
				<table class="table table-bordered">
					<thead>
						<tr>
							<th>代理ID</th>
							<th>购买数量</th>
							<th>购买的状态</th>
							<th>购买时间</th>
						</tr>
					</thead>
					<tbody id="dataList"></tbody>
				</table>
			</div>
			<div style="width: 100%;">
				<nav aria-label="Page navigation" >
					<div id="example">
						<ul id="pageShow" class="pull-left"></ul>
					</div>
				</nav>
			</div>
			<p><strong>说明</strong></p>
			<p>根据输入的时间段导出相对应的数据</p>
			<div class="form-group">
				<label for="start_time">开始时间</label>
				<input type="text" class="form-control" id="start_time" name="start_time" data-date-format="yyyy-mm-dd hh:ii:ss">
			</div>
			<div class="form-group">
				<label for="end_time">结束时间</label>
				<input type="text" class="form-control" id="end_time" name="end_time" data-date-format="yyyy-mm-dd hh:ii:ss">
			</div>
			<div style="margin: 10px auto;" id="exports" ><a onclick="handel(this)" class="btn btn-primary">数据导出excel</a></div>
		</div>
		<script type="text/javascript">
			$(function () {
                $( "#start_time" ).datetimepicker({
                    language: 'zh-CN',
                    autoclose: 1,
                    todayHighlight: 1,
                    weekStart: 1,
                    startDate: 0
                });
                $( "#end_time" ).datetimepicker({
                    language: 'zh-CN',
                    autoclose: 1,
                    todayHighlight: 1,
                    weekStart: 1,
                    startDate: 0
                });
            })
			showpage();
			function showpage(pages){
				var page=pages?pages:1;
				$.ajax({
					type:"get",
					dataType:"json",
					url:"{:U('Admin/Main/agentUserBuyPage')}",
					data:{page:page},
					success:function(data){
						var str = '';
						var time = '';
						var txt = '';
						if(data != 'error') {
							for(var i=0;i<data.data.length;i++) {
								var user = data.data[i].user_id;
								if(data.data[i].delete_tag == '0') {
									txt = "成功";
								}else if(data.data[i].delete_tag == '1') {
									txt = "失败";
								}
								str +="<tr><td class='user_id'>"+data.data[i].user_id+"</td><td>"+data.data[i].number+"</td><td>"+txt+"</td><td>"+getLocalTime(data.data[i].add_time)+"</td></tr>";
							}
							$("#dataList").html(str);
						}else{
							$("#dataList").html("没有任何数据");
						}

						var options = {
							currentPage: data.page,    //当前页，可以请求到数据再配置
							totalPages: data.pageSize,    //总共多少页，可以请求到数据再配置
							size:"normal",
							bootstrapMajorVersion: 3,//bootstrap版本
							// alignment:"right", 对齐方式
							numberOfPages:2,    //每一波显示几个
							itemTexts: function (type, page, current) {
								switch (type) {
									case "first": return "首页";
									case "prev": return "上一页";
									case "next": return "下一页";
									case "last": return "末页";
									case "page": return page;
								}
							},
							// 选择那页点击事件
							onPageClicked:function(event,originalEvent,type,page){
	//							console.log(page)//可以获取当前页，拿这个值去发请求即可
								showpage(page);
							},
						}
						$('#pageShow').bootstrapPaginator(options);
					}
				});
			}
			function handel(This) {
                var start_time = new Date($("#start_time").val()).getTime()/1000;
                var end_time = new Date($("#end_time").val()).getTime()/1000;

                if(start_time == '' || end_time == '') {
                    alert("导出数据的时间不能为空!");
                    window.location.href="{:U('Admin/Main/logExpend')}";
                    return false;
				}
                if(start_time > end_time && start_time == end_time) {
                    alert("请注意时间的先后顺序！");
                    window.location.href="{:U('Admin/Main/logExpend')}";
                    return false;
                }
				$(This).attr('href',"{:U('Admin/Main/buyListExport')}?start_time="+start_time+"&end_time="+end_time);
            }
		</script>
	</body>
</html>
